<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<%@ include file="/common/taglibs.jsp" %>
<c:set var="buttons">
    <input type="button" style="margin-right: 5px"   onclick="f_update()" value="<fmt:message key="button.check"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_save()" value="<fmt:message key="button.save"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_cancel()" value="<fmt:message key="button.cancel"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_query()" value="<fmt:message key="button.query"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_excel()" value="<fmt:message key="button.excel"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_print(1)" value="<fmt:message key="button.print.check"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_print(2)" value="<fmt:message key="button.print.grant"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_print(3)" value="打印学位签名表"/>
    <input type="button" style="margin-right: 5px"   onclick="f_print(4)" value="打印毕业签名表"/>
    <input type="button" style="margin-right: 5px"   onclick="f_printCert('xw')" value="打印学位证书"/>
    <input type="button" style="margin-right: 5px"   onclick="f_printCert('by')" value="打印毕业证书"/>
    <input type="button" style="margin-right: 5px"   onclick="f_printCert('jy')" value="打印结业证书"/>
    <input type="button" style="margin-right: 5px"   onclick="f_printCert('tz')" value="打印学位通知"/>
    <input type="button" style="margin-right: 5px"   onclick="f_back()" value="<fmt:message key="button.back"/>"/>
</c:set>
<div id='toolbar' style="display:none"> 
<c:out value="${buttons}" escapeXml="false"/>
</div>
  <div id="check_win" style="height:300px;display:none"></div>
<div id='fail_score_table_html' style='display:none'></div>

<script>
Ext.onReady(globalScope._ready);
var checkForm,checkWin,grid,htmlDiv;
var failScoreGrid;
var failScoreGridTable='V_FAIL_SCORE';
var userName='<authz:authentication operation="username"/>';
var account='<authz:authentication operation="firstName"/>';

var tableName="<c:out value='${model.tableName}'/>";
var tableAlias="<c:out value='${model.parameter.tableAlias}'/>";

Ext.onReady(function(){
  globalScope.grid.get(tableName).on('rowdblclick',f_update);
  
  htmlDiv=Ext.get("fail_score_table_html").dom;
  
  var tdiv=Ext.get("title").dom;
  tdiv.innerHTML="<B><c:out value='${model.parameter.graduateYear}'/>届<c:out value='${model.parameter.gradeMajorName}'/>专业毕业生审核</B>";
  if(tableAlias!="")  tdiv.innerHTML="<B><c:out value='${model.parameter.graduateYear}'/>届未获学位学生毕业审核</B>";
  var stateColumn,degreeColumn;
  grid=globalScope.grid.get("<c:out value='${model.parameter.tableName}'/>");
   var span=Ext.get(tableName+"_columns").dom;
    var columns=Ext.decode(span.innerText);
  Ext.each(columns,function(c){
    if(c.name=='GRADUATE_STATE') stateColumn=c;
    if(c.name=='GRANTED_DEGREE') degreeColumn=c;
  });
  checkForm=new Ext.form.FormPanel({
        labelAlign: 'right',
        labelWidth:80,
        frame:true,
        url:'form.jsp',
        autoHeight:true,
        autoWidth:true,
        items:[
	        {layout:'column',items:[
		        {columnWidth:.5,layout:'form',items:[{xtype:'textfield',fieldLabel:'学号',id:'STUDENT_NO',readOnly:true}]},
		        {columnWidth:.5,layout:'form',items:[{xtype:'textfield',fieldLabel:'姓名',id:'STUDENT_NAME',readOnly:true}]}
		    ]},
	        {layout:'column',items:[
		        {columnWidth:.5,layout:'form',items:[{
		            xtype:'combo',   
		            fieldLabel:stateColumn.text,   
		            store: new Ext.data.SimpleStore(stateColumn.store),   
		            editable: false,   
		            hiddenName:stateColumn.name,   
		            displayField:'text',   
		            valueField:'value',   
		            typeAhead:true,   
		            mode: 'local',   
		            triggerAction: 'all',   
		            emptyText:'请选择',   
		            selectOnFocus:true,   
		            resizable:true,   
		            anchor:'90%',
		            forceSelection:true           
                }]},
		        {columnWidth:.5,layout:'form',items:[{
		            xtype:'combo',   
		            fieldLabel:degreeColumn.text,   
		            store: new Ext.data.SimpleStore(degreeColumn.store),   
		            editable: false,   
		            hiddenName:degreeColumn.name,   
		            displayField:'text',   
		            valueField:'value',   
		            typeAhead:true,   
		            mode: 'local',   
		            triggerAction: 'all',   
		            emptyText:'请选择',   
		            selectOnFocus:true,   
		            resizable:true,   
		            anchor:'90%',
		            forceSelection:true           
                }]}
		    ]},
		    {xtype:'textarea',name:'NOTE',fieldLabel:'备注',width:480,height:100}
        ]
  });
  
  
  globalScope._model({tableName:'V_FAIL_SCORE',quickWhere:' 1=2 '},function(responseText){
	     htmlDiv.innerHTML=responseText;
	     var span=Ext.get(failScoreGridTable+"_columns").dom;
	     var columns=Ext.decode(span.innerText);
	     failScoreGrid= new Ext.quick.QuickGrid(failScoreGridTable, {
		     id:'c_fail_score_grid',
		     collapsible:true,
		     split:true,
		     stripeRows: true, 
		     enableDragDrop:false,
		     title:'不及格课程(注:如果将课程勾选,说明该课程为该学生毕业该选而未及格的课程)',
		     clicksToEdit:1,
		     'remove':true,
		     height:200,
		     'smConfig':{}
	    },columns);
  
	    Ext.get('check_win').dom.innerHTML="";
		checkWin = new Ext.Window({
		    layout:'fit',
		    el:'check_win',
		    title: "毕业审核",
		    width:600,
		    autoScroll:true,
		    modal:true,
		    autoHeight:true,
		    closeAction:'hide',
		    buttonAlign:'center',
		    items: [ checkForm,
		             {id:'c_fail_score_panel',region:'center',layout:'fit',items:[failScoreGrid] }
		           ],
		    buttons: [{
		        text:"确定",
		        handler:function(){
		          var r=null;
		          r=grid.getSelectionModel().getSelected();
		          checkForm.getForm().updateRecord(r);
		          
		          var str1="";
		          var smodel=failScoreGrid.getSelectionModel();
		          var failGridStroe=failScoreGrid.getStore();
		          failGridStroe.each(function(rr){
		            if(smodel.isSelected(rr)){
		              str1+=rr.get("COURSE_NO")+",";
		            }
		          });
		          r.set("FAIL_COURSES",str1);
		          if(r.dirty){
		            r.set('CHECK_FLAG','02');
		            r.set('CHECK_ACCOUNT',userName+'('+account+')');
		            var dt=new Date();
		            r.set('CHECK_TIME',dt.format('Y-m-d H:i:s'));
		          }
		          
		          checkWin.hide();
		        }
		    },{
		        text:jspVarHandler.fmt_button_close,
		        handler:function(){checkWin.hide()}
		    }]
		});
	    checkWin.render(document.body);
	    checkWin.hide();
    }); 
});

function f_print(flag){
 if(flag==1){
   jasper='/web-inf/pages/graduate/print/graduateExamine.jasper'
 }else if(flag==2){
   jasper='/web-inf/pages/graduate/print/graduate.jasper'
 }else if(flag==3){
   jasper='/web-inf/pages/graduate/print/graduateSign.jasper'
 }else{
   jasper='/web-inf/pages/graduate/print/graduateSign2.jasper'
 }
 var matrix=[['jasper',jasper],
         ['params','BYNF[$]<c:out value='${model.parameter.graduateYear}'/>'],
         ['params','ZYDM[$]<c:out value='${model.parameter.MAJOR}'/>']
       ];
  var form=createForm(g_rootPath+'/pdf/print.html',matrix);
  form.target="_blank";
  form.submit();
  
}

function f_printCert(typ){
  var jasper='';
 switch(typ){
   case 'xw': jasper='/web-inf/pages/graduate/print/degreeCert.jasper';break;
   case 'by': jasper='/web-inf/pages/graduate/print/diplomaCert.jasper';break;
   case 'jy': jasper='/web-inf/pages/graduate/print/completionCert.jasper';break;
   case 'tz': jasper='/web-inf/pages/graduate/print/degreeNotice.jasper';break;
 }
 var matrix=[['jasper',jasper],
         ['params','BYNF[$]<c:out value='${model.parameter.graduateYear}'/>'],
         ['params','ZYDM[$]<c:out value='${model.parameter.MAJOR}'/>'],
         ['params','XH[$]%']
       ];
  var form=createForm(g_rootPath+'/pdf/print.html',matrix);
  form.target="_blank";
  form.submit();
 }

function f_update(){

  var r=globalScope.grid.get(tableName).getSelectionModel().getSelected();
  if(Ext.isEmpty(r)){
    Ext.Msg.alert('WARNING',jspVarHandler.fmt_info_required_update_record);
    return false;
  }
  var studentNo=r.get('STUDENT_NO');
  var studentName=r.get('STUDENT_NAME');
  var graduateState=r.get('GRADUATE_STATE');
  var grantedDegree=r.get('GRANTED_DEGREE');
  var failCourses=r.get('FAIL_COURSES');
  var courseArray=[];
  if(Ext.isEmpty(failCourses)==false){
    courseArray=failCourses.split(",");
  }
  
  var note=r.get('NOTE');
  checkForm.getForm().setValues({'STUDENT_NO':studentNo,'STUDENT_NAME':studentName,'GRADUATE_STATE':graduateState,'GRANTED_DEGREE':grantedDegree,'NOTE':note});
  
  
  globalScope._model({tableName:'V_FAIL_SCORE',STUDENT_NO:studentNo,COURSE_TYPE:'1'},function(responseText){
     htmlDiv.innerHTML=responseText;
     var htmlTable=Ext.get(failScoreGridTable);
     failScoreGrid.reloadData(htmlTable);	
     f_select();     
  });
  
  checkWin.show();
}


function f_select(){
  var r=globalScope.grid.get(tableName).getSelectionModel().getSelected();
  if(Ext.isEmpty(r)){
    Ext.Msg.alert('WARNING',jspVarHandler.fmt_info_required_update_record);
    return false;
  }
  var failCourses=r.get('FAIL_COURSES');
  var courseArray=[];
  if(Ext.isEmpty(failCourses)==false){
    courseArray=failCourses.split(",");
  }
   var smodel=failScoreGrid.getSelectionModel();
   var gridStore=failScoreGrid.getStore();
   var sz=gridStore.getCount();
   
   var recs=[];
   for(var i=0;i<sz;i++){
     var r=gridStore.getAt(i);
     var courseNo=r.get('COURSE_NO');
     var s1=courseArray.indexOf(courseNo);
     if(s1!=-1){
       recs.push(i);
     }
   }
   smodel.selectRows(recs);
}

function f_back(){
  location=g_rootPath+"educational/graduate/check/single.html";
}
function f_excel(){
  globalScope._exportExcel();
//  globalScope._excel();
}

function f_add(tableName){
  globalScope._add(tableName);
}


function f_delete(tableName){
  globalScope._delete(tableName);
} 

function f_cancel(tableName){
  globalScope._cancel(tableName);
}

function f_save(tableName,url){
  globalScope._save(tableName,url);
}

function f_query(tableName){
    globalScope._query(tableName);
}
function f_gotoPage(pageNo,rowsOfPage,pageCount,rowCount,conditoin){
  globalScope._gotoPage({dealCookie:true,spanName:"g_pageSpan_<c:out value='${model.tableName}'/>",pageNo:pageNo,rowsOfPage:rowsOfPage,pageCount:pageCount,rowCount:rowCount,condition:conditoin,tableName:"<c:out value='${model.tableName}'/>"},{GRADE:'<c:out value='${model.parameter.GRADE}'/>',MAJOR:'<c:out value='${model.parameter.MAJOR}'/>'});
}
</script>
